package jsyf.oa.web.system;

import com.alibaba.fastjson.JSONObject;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.FastJsonConvert;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.system.User2GroupFacade;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Created by Administrator on 2018/1/1 0001.
 */
@Api(value = "自定义分组接口", description = "自定义接口")
@Controller
@RequestMapping("/user2Group")
public class User2GroupController {
    @Resource
    private User2GroupFacade user2GroupFacade;

    @RequestMapping(value = "/config.json", method = RequestMethod.POST)
    public void config(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParam = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        Boolean result = user2GroupFacade.config(jsonParam.getString("userIds"), jsonParam.getString("groupId"));
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(String.valueOf(result)));
    }
    @RequestMapping(value = "/removeByUserIdAndGroupId.json", method = RequestMethod.POST)
    public void removeByUserIdAndGroupId(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParam = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        String userId=jsonParam.getString("userId");
        String groupId=jsonParam.getString("groupId");
        String result = this.user2GroupFacade.removeByUserIdAndGroupId(userId,groupId);
        ResponseUtils.putJsonResponse(response, result);
    }

}
